<template>
  <view class="page custom-page custom-tabbar home">
    <custom-head>
      <div class="home_head flex a-center j-center" @tap="selectShow = !selectShow">
        <view class="title">{{ schoolName }}</view> <u-icon name="arrow-down" color="#8F9399" size=" 26"></u-icon>
      </div>
      <head-select :id.sync="active" :visible.sync="selectShow" @select="handelSelect"></head-select>
    </custom-head>
    
    <div class="card">
      <div class="title flex a-center jlr">
        <view class="label">学校管理</view>
        <view class="more flex a-center">
          <text>更多</text>
          <u-icon name="arrow-right" color="#8F9399" size="24"></u-icon>
        </view>
      </div>
      <view class="schoolManagement homeCard flex wrap">
        <view class="item flex col a-center j-center" @tap="enter('student')">
          <view class="icon i1"></view>
          <text class="text">全部学生</text>
        </view>
        <view class="item flex col a-center j-center" @tap="enter('school')">
          <view class="icon i2"></view>
          <text class="text">学校信息</text>
        </view>
        <view class="item flex col a-center j-center" @tap="enter('class')">
          <view class="icon i3"></view>
          <text class="text">班级管理</text>
        </view>
        <view class="item flex col a-center j-center" @tap="enter('teacher')">
          <view class="icon i4"></view>
          <text class="text">老师管理</text>
        </view>
        <view class="item flex col a-center j-center" @tap="enter('news')">
          <view class="icon i5"></view>
          <text class="text">每日动态</text>
        </view>
      </view>
    </div>

    <view class="card">
      <view class="title flex a-center jlr">
        <view class="label">积分管理</view>
        <view class="more flex a-center">
          <text>更多</text>
          <u-icon name="arrow-right" color="#8F9399" size="24"></u-icon>
        </view>
      </view>
      <view class="gradeManagement homeCard flex wrap">
        <view class="item flex col a-center j-center" @click="clickDown('addIntegral')">
          <view class="icon i6"></view>
          <text class="text">发放积分</text>
        </view>
        <view class="item flex col a-center j-center" @click="clickDown('projectStencil')">
          <view class="icon i7"></view>
          <text class="text">积分模板</text>
        </view>
        <view class="item flex col a-center j-center" @click="clickDown('sendBox')">
          <view class="icon i8"></view>
          <text class="text">发放宝箱</text>
        </view>
        <view class="item flex col a-center j-center" @click="clickDown('treasureBox')">
          <view class="icon i9"></view>
          <text class="text">宝箱管理</text>
        </view>
        <view class="item flex col a-center j-center"  @click="clickDown('dynamic')">
          <view class="icon i10"></view>
          <text class="text">积分动态</text>
        </view>
        <view class="item flex col a-center j-center" @click="clickDown('integral')">
          <view class="icon i11"></view>
          <text class="text">每日签到</text>
        </view>
      </view>
    </view>

    <view class="card">
      <view class="title flex a-center jlr">
        <view class="label">商城管理</view>
        <view class="more flex a-center">
          <text>更多</text>
          <u-icon name="arrow-right" color="#8F9399" size="24"></u-icon>
        </view>
      </view>
      <view class="ishopManagement homeCard flex wrap">
        <view class="item flex col a-center j-center" @click="handleJump('giftManage')">
          <view class="icon i12"></view>
          <text class="text">礼品管理</text>
        </view>
        <view class="item flex col a-center j-center"  @click="handleJump('gift')">
          <view class="icon i13"></view>
          <text class="text">发放礼品</text>
        </view>
        <view class="item flex col a-center j-center" @click="handleJump('stock')">
          <view class="icon i14"></view>
          <text class="text">库存管理</text>
        </view>
      </view>
    </view>
    <custom-tabbar></custom-tabbar>
  </view>
</template>

<script>
import { notLogin } from '../../utils/getData'
export default {
  data() {
    return {
      active: this.school?.id,
      selectShow: false,
      schoolName: '',
    }
  },
  
  mounted() {
    // console.log('全局数据', getApp().globalData)
    this.active = this.school?.id
    this.schoolName = this.glbSchoolName
    notLogin()
  },

  methods: {
    handleJump(param) { // 商城管理跳转
      if (param === 'stock') {
        uni.navigateTo({
          url: '/pages/home/homeStockManage'
        })
      } else if (param === 'gift') {
        uni.navigateTo({
          url: '/pages/student/gift'
        })
      } else if (param === 'giftManage') {
        uni.navigateTo({
          url: '/pages/home/giftManage'
        })
      }
      
    },
    enter(name) {
      uni.navigateTo({
        url: `/pages/${name}/${name}`
      })
    },

    clickDown(name) {
      console.log('aa name', name)
      if (name === 'integral') {
        uni.navigateTo({
          url: `/pages/home/honeIntegral`
        })
      } else if (name === 'dynamic') {
        uni.navigateTo({
          url: `/pages/home/honeIntegralDynamic`
        })
      } else if (name === 'treasureBox') {
        uni.navigateTo({
          url: '/pages/student/treasureBox'
        })
      } else if (name === 'sendBox') {
        uni.navigateTo({
          url: `/pages/home/sendBox`
        })
      } else if (name === 'projectStencil') {
        uni.navigateTo({
          url: `/pages/home/projectStencil`
        })
      } else if (name === 'addIntegral') {
        uni.navigateTo({
          url: `/pages/home/addIntegral`
        })
      }
      
    },

    handelSelect(e) {
      getApp().globalData.glb_list.glbId = e; // 获取全局选中的 id，哪个学校
      console.log(e, '测试---', getApp().globalData.school)
      // console.log('哪个学校的',getApp().globalData.schools )
      let selectSchool = getApp().globalData.schools.filter(i => i.id === e)[0]
      this.schoolName = selectSchool.name
      getApp().globalData.glb_list.glbSchoolName = selectSchool.name;

      console.log('000', selectSchool.students)
      console.log('111', selectSchool)

      getApp().globalData.school = {
        ...getApp().globalData.school,
        ...selectSchool
      }
      this.active = e
    }
  },
}
</script>

<style scoped lang="scss">
$color: #303133;

.home_head {
  font-size: 32rpx;
  color: $color;
  position: relative;
  z-index: 99;
  background-color: #fff;

  .title {
    margin-right: 10rpx;

    &:active {
      filter: brightness(200%);
    }
  }
}

.card {
  background-color: #fff;
  margin-top: 20rpx;
  padding: 40rpx;
  padding-bottom: 0;

  .title {
    width: 100%;
    font-size: 34rpx;
    color: #040709;
    margin-bottom: 45rpx;

    .more {
      color: #606265;
      font-size: 24rpx;

      text {
        margin-right: 8rpx;
      }

      &:active {
        filter: brightness(80%);
      }
    }
  }
}

.homeCard {
  width: 100%;

  .item {
    width: 25%;
    margin-bottom: 50rpx;
  }

  .item:active {
    filter: brightness(80%);
  }

  .icon {
    width: 98rpx;
    height: 98rpx;
    margin-bottom: 18rpx;

    &.i1 {
      background: url('@/static/img/home01.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i2 {
      background: url('@/static/img/home02.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i3 {
      background: url('@/static/img/home03.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i4 {
      background: url('@/static/img/home04.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i5 {
      background: url('@/static/img/home05.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i6 {
      background: url('@/static/img/home06.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i7 {
      background: url('@/static/img/home07.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i8 {
      background: url('@/static/img/home08.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i9 {
      background: url('@/static/img/home09.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i10 {
      background: url('@/static/img/home10.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i11 {
      background: url('@/static/img/home11.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i12 {
      background: url('@/static/img/home12.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i13 {
      background: url('@/static/img/home13.png') no-repeat;
      background-size: 100% 100%;
    }

    &.i14 {
      background: url('@/static/img/home14.png') no-repeat;
      background-size: 100% 100%;
    }
  }

  .text {
    text-align: center;
    font-size: 28rpx;
    color: $color;
  }
}
</style>
